<div class="form">


<?php $form = $this->beginWidget('GxActiveForm', array(
	'id' => 'categories-form',
	'enableAjaxValidation' => false,
));
?>

	<p class="note">
		<?php echo Yii::t('app', 'Fields with'); ?> <span class="required">*</span> <?php echo Yii::t('app', 'are required'); ?>.
	</p>

	<?php echo $form->errorSummary($model); ?>
		<div class="row">
		<?php echo $form->labelEx($model,'published'); ?>
		<?php echo $form->checkBox($model, 'published'); ?>
		<?php echo $form->error($model,'published'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'parent_id'); ?>
		<?php 
			$meid = ($model->id!=0)?$model->id:0;
			$cats = Categories::model()->findAll('published=:p ORDER BY position ASC', array(':p'=>1));
			$listdata = CHtml::listData($cats, 'id', 'title_tree');
			echo '<select name="Categories[parent_id]" id="Categories_parent_id">';
			echo '<option value="">--None--</option>';
			foreach($listdata as $key => $cat):
				if($key==$meid){
					echo "<option disabled='disabled'>$cat</option>";
				}else{
					if($model->parent_id==$key){
						$selected = "selected";
					}else{
						$selected="";
					}
					echo "<option value='$key' $selected>$cat</option>";
				}
				
			endforeach;
			echo '</select>';
		?>
		<?php echo $form->error($model,'parent_id'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model, 'title', array('maxlength' => 255, 'style'=>'width:400px;')); ?>
		<?php echo $form->error($model,'title'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'alias'); ?>
		<?php echo $form->textField($model, 'alias', array('maxlength' => 255, 'style'=>'width:400px;')); ?>
		<?php echo $form->error($model,'alias'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'description'); ?>
		<?php echo $form->textArea($model, 'description', array('class'=>'textarea-m')); ?>
		<?php echo $form->error($model,'description'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'ordering'); ?>
		<?php echo $form->textField($model, 'ordering'); ?>
		<?php echo $form->error($model,'ordering'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'created'); ?>
		<?php 
			$this->widget('ext.widgets.CJuiDateTimePicker.CJuiDateTimePicker',array(
		        'model'=>$model, //Model object
		        'attribute'=>'created', //attribute name
		        'mode'=>'datetime', //use "time","date" or "datetime" (default)
				'options'=>array()
		    ));
		?>
		<?php echo $form->error($model,'created'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'created_by'); ?>
		<?php 
		$u_create = iUsers::model()->findByPk($model->created_by);
		if(is_object($u_create))
			echo $u_create->username;
		?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'modified'); ?>
		<?php 
			$this->widget('ext.widgets.CJuiDateTimePicker.CJuiDateTimePicker',array(
		        'model'=>$model, //Model object
		        'attribute'=>'modified', //attribute name
		        'mode'=>'datetime', //use "time","date" or "datetime" (default)
				'options'=>array()
		    ));
		?>
		<?php echo $form->error($model,'modified'); ?>
		</div><!-- row -->
		<div class="row">
		<?php echo $form->labelEx($model,'modified_by'); ?>
		<?php 
		$u_modified = iUsers::model()->findByPk($model->modified_by);
		if(is_object($u_modified))
			echo $u_modified->username;
		?>
		</div><!-- row -->

<?php
echo GxHtml::submitButton(Yii::t('app', 'Save'), array('id'=>'s-bt','style'=>'display: none'));
$this->endWidget();
?>
</div><!-- form -->
<script type="text/javascript">
jQuery(document).ready(function(){
	jQuery("#Categories_title").blur(function(){
		jQuery.ajax({
			url: '<?php echo Yii::app()->createUrl('/admin_news/common/renalias');?>',
			data: {title:this.value},
			dataType:'json',
			success: function(msg){
			   	jQuery("#Categories_alias").attr("value",msg.title)
			  }
		})
	})
})
</script>